package com.hdax.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdax.entity.Activity;
import com.hdax.dao.ActivityMapper;
import com.hdax.service.ActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 活动表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-03-22
 */
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {

    @Autowired
    private ActivityMapper as;
    @Override
    public Map<String, Object> listByPage(int page, int pageSize, Activity name) {
       Page<Activity> a=new Page<Activity>(page,pageSize);
        QueryWrapper queryWrapper=new QueryWrapper();
        if(name!=null){
            if (name.getName()!=null && !name.getName().trim().equals("")){
                queryWrapper.like("name",name.getName());
            }
        }
        IPage iPage=page(a,queryWrapper);
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("data",iPage.getRecords());
        map.put("count",iPage.getTotal());
        return map;
    }

    @Override
    public int add(Activity activity) {
        return as.add(activity);
    }

    @Override
    public int update(Activity activity) {
        return as.update(activity);
    }

    @Override
    public int btnDel(List<Integer> ids) {
        return baseMapper.btnDel(ids);
    }

}
